package com.mjh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mjh.bean.ActivityRemark;
import com.mjh.mapper.ActivityRemarkMapper;
import com.mjh.service.ActivityRemarkService;
import com.mjh.utils.AuthUtil;
import com.mjh.vo.ActivityRemarkVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityRemarkServiceImpl implements ActivityRemarkService {
    @Autowired
    private ActivityRemarkMapper activityRemarkMapper;
    @Override
    public PageInfo<ActivityRemarkVo> queryActivityRemarkInfoPage(Integer current, Integer size, Integer activityId) {
        PageHelper.startPage(current,size);
        List<ActivityRemarkVo> list = activityRemarkMapper.selectList(activityId);
        return new PageInfo<>(list);
    }

    @Override
    public Boolean saveActivityRemark(ActivityRemark activityRemark) {
        activityRemark.setCreateTime(new Date());
        activityRemark.setCreateBy(AuthUtil.getLoginUserId());
        activityRemark.setDeleted(0);
        return  activityRemarkMapper.insert(activityRemark)>0;
    }

    @Override
    public Boolean removeActivityRemark(Integer id) {
        ActivityRemark activityRemark = new ActivityRemark();
        activityRemark.setId(id);
        activityRemark.setDeleted(1);
        return activityRemarkMapper.updateByPrimaryKeySelective(activityRemark)>0;
    }

    @Override
    public ActivityRemark queryActivityRemarkById(Integer id) {

        return activityRemarkMapper.selectByPrimaryKey(Long.valueOf(id));
    }

    @Override
    public Boolean modifyActivityRemark(ActivityRemark activityRemark) {
        activityRemark.setEditTime(new Date());
        activityRemark.setEditBy(AuthUtil.getLoginUserId());
        return activityRemarkMapper.updateByPrimaryKeySelective(activityRemark)>0;
    }
}
